﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WebEntities;
using WebEntities.Models.WebInfo;

namespace com.subb.WebInformation
{
    public class WI_ExpertCataDAL
    {
        public List<WI_ExpertCata> GetAllExpertCata(int start, int limit, out int ttlCount)
        {
            ttlCount = 0;
            using (WebsiteDbEntities ctx = new WebsiteDbEntities())
            {
                ctx.ContextOptions.LazyLoadingEnabled = false;
                var query = ctx.WI_ExpertCata.OrderBy(c => c.ExpertCataID);
                ttlCount = query.Count();
                List<WI_ExpertCata> catalist = query.Skip(start).Take(limit).ToList();
                return catalist;
            }
        }


        public WI_ExpertCata GetExpertCata(int cataId)
        {
            using (WebsiteDbEntities ctx = new WebsiteDbEntities())
            {
                ctx.ContextOptions.LazyLoadingEnabled = false;
                WI_ExpertCata ncata = ctx.WI_ExpertCata.SingleOrDefault(c => c.ExpertCataID == cataId);
                return ncata;
            }
        }

        public List<WI_ExpertCata> GetAllExpertCata()
        {
            using (WebsiteDbEntities ctx = new WebsiteDbEntities())
            {
                ctx.ContextOptions.LazyLoadingEnabled = false;
                var query = ctx.WI_ExpertCata;
                List<WI_ExpertCata> pcatalist = query.ToList();
                return pcatalist;
            }
        }

        public void CreateExpertCata(WI_ExpertCata addObj)
        {
            using (WebsiteDbEntities ctx = new WebsiteDbEntities())
            {
                ctx.WI_ExpertCata.AddObject(addObj);
                ctx.SaveChanges();
            }
        }

        public bool UpdateExpertCata(int cataId, ExpertCata v_ExpertCata)
        {
            bool result = false;
            using (WebsiteDbEntities ctx = new WebsiteDbEntities())
            {
                WI_ExpertCata ncata = ctx.WI_ExpertCata.SingleOrDefault(c => c.ExpertCataID == cataId);
                if (ncata != null)
                {
                    ncata.ExpertCataName = v_ExpertCata.ExpertCataName;
                   
                    ctx.SaveChanges();
                    result = true;
                }
            }
            return result;
        }

        public bool RemoveExpertCata(int cataId)
        {
            bool result = false;
            using (WebsiteDbEntities ctx = new WebsiteDbEntities())
            {
                WI_ExpertCata ncata = ctx.WI_ExpertCata.SingleOrDefault(c => c.ExpertCataID == cataId);
                if (ncata != null)
                {
                    ctx.WI_ExpertCata.DeleteObject(ncata);
                    ctx.SaveChanges();
                    result = true;
                }
            }
            return result;
        }
    }
}
